/**
 * Arduino两轮小车教程
 * 
 * car0801: 
 * 
 * site: http://www.xpstem.com/
 * author: billy zhang
 */
#ifndef ARDUINO_INFRARED_FOLLOW_VEHICLE_H_
#define ARDUINO_INFRARED_FOLLOW_VEHICLE_H_

#include <Servo.h>
#include <IRremote.h>
#include "XPVehicle.h"
#include "UltrasonicLidar.h"
#include "TwoWheelDriven.h"

/**
 * 红外线跟随小车类
 * 
 * 小车寻找红外遥控器发出的信号，并做出跟随动作。
 * 需红外接收管、红外遥控器、超声波测距传感器、舵机配套使用。
 */
class InfraredFollowVehicle : public XPVehicle
{
   public:
     InfraredFollowVehicle(const TwoWheelDriven& driven, const LedController& ledCtrl, 
          const UltrasonicLidar& lidar, uint8_t irrecvPin)
      : XPVehicle(driven, ledCtrl), lidar_(lidar), irrecv_(IRrecv(irrecvPin))
     {
     }

    void setup() override;
     void drive() override;
     
     ~InfraredFollowVehicle();

  private:

    void lookAngle(uint8_t angle);
    int lookAround();

    const IRrecv& irrecv_;
    const UltrasonicLidar& lidar_;
    
};

#endif
